package com.donquijote.spring.bean;

import org.springframework.beans.factory.FactoryBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-11-14 17:11
 */
public class DateFactory implements FactoryBean<Date> {

    private String date;

    public DateFactory(String date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "DateFactory{" +
                "date='" + date + '\'' +
                '}';
    }

    @Override
    public Date getObject() throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date birthday = simpleDateFormat.parse(date);//把String字符串转换成特定格式的Date类型
        return birthday;
    }

    @Override
    public Class<?> getObjectType() {
        return null;
    }
}
